package com.algorithm;

import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;
import java.util.PriorityQueue;

public class DelayedRemove {

    public static void main(String[] args) {
        //优先级队列延迟删除
        PriorityQueue<Integer> heap = new PriorityQueue<>(Comparator.reverseOrder());
        Map<Integer, int[]> delayed = new HashMap<>();
        while (!heap.isEmpty()) {
            Integer peek = heap.peek();
            int[] vals = delayed.get(peek);
            if (vals != null) {
                vals[0]--;
                if (vals[0] == 0) {
                    delayed.remove(peek);
                }
                heap.poll();
            } else {
                break;
            }
        }
    }

}
